<?php
class Mwc_SystemPoint_Model_Log extends Mage_Core_Model_Abstract{
    protected function _construct(){
        $this->_init('systempoint/log');
    }

    public function getMembershipId(){
        return $this->getId();
    }
    
	public function getUserEmail(){
	        return $this->_getData('user_email');
	}
	
	public function getTitle(){
	        return $this->_getData('title');
	}
	
	public function getPoint(){
	        return $this->_getData('point');
	}
	
	public function getLogDate(){
	        return $this->_getData('log_date');
	}
	
    public function loadOldestByEmail($email){
    	//$model = Mage::getModel('systempoint/userpoint');
        $lastrow = $this->getCollection()
        			->addFieldToFilter('user_email', $email)
        			->addFieldToFilter('log_date', array('lteq' => date('Y-m-d H:i:s', mktime())))
        			->setOrder('log_date','ASC')
        			->setPageSize(1);
        $arr[]='';        
	    foreach($lastrow as $item){
            $arr['user_email'] = $item->getUserEmail();
            $arr['title'] = $item->getTitle();
            $arr['point'] = $item->getPoint();
            $arr['log_date'] = $item->getLogDate();
        }
        return $arr;
    }
    
    public function checkLog($title, $email){
    	$row = $this->getCollection()
        			->addFieldToFilter('user_email', $email)
        			->addFieldToFilter('title', $title);
        $arr[]='';        
	    foreach($row as $item){
            return TRUE;
        }
        return FALSE;
    }

    public function getIcon(){
        $model = Mage::getModel('systempoint/membership');
        $lastrow = $model->getCollection()
            ->addFieldToFilter('number_of_point', array('lteq' => $this->getPoint()))
            ->setOrder('number_of_point','DESC')
            ->getFirstItem()->getIconPath();

        return $lastrow;
    }
}